<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form method="get" class="form-horizontal" id="saveForm">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">分类</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" name="typeId">
                                    <option value="0">请选择</option>
                                {{range .ProductTypes}}
                                    <option value="{{.Id}}">{{.Title}}</option>
                                {{end}}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">名称</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="title">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">价格</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="price">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">库存</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="stock">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="image">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group">
                            <label class="col-sm-2 control-label">详情</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="detail">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="button" id="saveBtn">保存</button>
                                <button class="btn btn-white" type="button">取消</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

{{define "admin/product/add_edit-footer"}}
<script>
    $(document).on('click', '#saveBtn', function () {
        var formVal = tips.getFormValues("#saveForm");
        console.log(formVal);
        $.ajax({
            type: 'post',
            url: '/admin/product',
            data: formVal,
            success: function (result) {
                if (result.status === true) {
                    layer.msg(result.message, {icon: 6});
                } else {
                    layer.alert(result.message, {icon: 5});
                }
            },
            error: function () {
                layer.alert("异步请求失败", {icon: 5});
            }
        });

    });
</script>
{{end}}